$(() => {






    let shijian = function () {
        layui.use('laydate', function () {
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#articleDate' //指定元素
            })
        })

    }
    shijian()


    let fuWenBen = function () {
        tinymce.init({
            selector: '#articleContent',
            language: 'zh_CN'
        });
    }
    fuWenBen()


    let getCategoryList = function () {
        myAjax('get', '/admin/category/list', {}, (res) => {
            let htmlStr = template('moban', res)
            $('#category').html(htmlStr)
        })
    }
    getCategoryList()


    let state = ''
    $('#form').on('submit', function (e) {
        e.preventDefault()
        let fd = new FormData($('#form')[0])
        fd.append('state', state)
        fd.forEach((value, key) => {
            console.log({ key, value });
        })

        myAjax('post', "/admin/article/publish", fd, (res) => {
            if (res.code === 200) {
                // console.log('成功');
                layer.msg(res.msg, { icon: 1, time: 2000 }, () => {
                    location.href = 'article_list.html'
                })
            } else {
                layer.msg(res.msg, { icon: 3, time: 2000 })
            }
        })
        // $.ajax({
        //     type: 'post',
        //     url: 'http://localhost:8080/api/v1/admin/article/publish',
        //     data: fd,
        //     headers: {
        //         Authorization: localStorage.getItem('dsj_token')
        //     },
        //     contentType: false,
        //     processData: false,
        //     success: (res) => {
        //         if (res.code === 200) {
        //             // console.log('成功');
        //             layer.msg(res.msg, { icon: 1, time: 2000 }, () => {
        //                 location.href = 'article_list.html'
        //             })
        //         } else {
        //             layer.msg(res.msg, { icon: 3, time: 2000 })
        //         }
        //     }
        // })
    })

    $('.btn-add').on('click', function () {
        state = '已发布'
    })
})